﻿#region Copyright and Licensing Notice
// Copyright (C) 2011 Steven Bosnick
// 
// This program is open source software; you can redistribute it 
// and/or modifiy it under the terms of the Eclipse Public License,
// version 1.0.
// 
// This program is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A 
// PARTICULAR PURPOSE. See the Eclipse Public License for more
// details.
// 
// You should have received a copy of the Eclipse Public License 
// along with this program; if not, you can find a copy at
// "http://www.opensource.org/licenses/eclipse-1.0.php".
#endregion
using System;
using System.Runtime.InteropServices;

namespace BitwiseOre.SharedMemory.Core.Primatives
{
    internal static class QueueConstants
    {
        public const int NullIndex = CountedIndex.MaxIndex;
        public const int MaxQueueIndex = CountedIndex.MaxIndex - 2;

        public const int IndexQueueLayoutCount = 3;
        private const int IndexQueueLayoutElementSize = sizeof (int);

        public const int PendingDequeuesCount = 1;
        private const int PendingDequeuesElementSize = sizeof (int);

        private static readonly int GuidQueueHeaderSize = Marshal.SizeOf(typeof (GuidQueueHeader));
        private const int GuidQueueIndexQueueCount = 2;

        private const int NextArrayElementSize = sizeof (int);
        public static readonly int GuidQueueElementSize = Marshal.SizeOf(typeof (Guid));

        public static readonly int GuidQueueFixedSize =
            GuidQueueHeaderSize + 
            PendingDequeuesCount*PendingDequeuesElementSize +
            GuidQueueIndexQueueCount*IndexQueueLayoutCount*IndexQueueLayoutElementSize;

        public static readonly int GuidQueueVariableSize =
            NextArrayElementSize + GuidQueueElementSize;

        private static readonly int ConnectionBufferHeaderSize = Marshal.SizeOf(typeof (ConnectionBufferHeader));

        private const int LengthsArrayElementSize = sizeof (int);
        private const int LengthsArrayCount = 2;

        private const int BufferElementSize = sizeof (byte);

        public static readonly int ConnectionBuffersFixedSize = ConnectionBufferHeaderSize;

        public const int ConnectionBuffersVariableSize = LengthsArrayElementSize*LengthsArrayCount;

        public const int ConnectionBuffersBufferSize = BufferElementSize*LengthsArrayCount;
    }
}